import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class PanelButton extends JPanel {
	private String source;
	private Image normalBackGround;
	private Image focusedBackGround;
	private boolean focused;
	
	public PanelButton(String sourceImageName) {
		focused = false;
		this.setOpaque(false);
		source = sourceImageName;
		normalBackGround = (new ImageIcon(getClass().getResource(
				source + "1.png"))).getImage();
		focusedBackGround = (new ImageIcon(getClass().getResource(
				source + "2.png"))).getImage();
		this.addMouseListener(new MouseAdapter() {
			   public void mouseEntered(MouseEvent e2) {
						 focused = true;
						 paintComponent(getGraphics());
			   }
		});
		
		this.addMouseListener(new MouseAdapter() {
			public void mouseExited(MouseEvent e) {
			      focused = false;
			      paintComponent(getGraphics());
			    }
		});

	}
	public void paintComponent(Graphics g)	{
		super.paintComponent(g);
		if ( focused )g.drawImage(focusedBackGround, 0, 0, normalBackGround.getWidth(this), normalBackGround.getHeight(this), this);
		else g.drawImage(normalBackGround, 0, 0, normalBackGround.getWidth(this), normalBackGround.getHeight(this), this);
	}
	
	public void setFocused(boolean status){
		focused = status;
	}
}
